/**
 * Created by Administrator on 2016-12-26.
 */





const util = require('util');
const EventEmitter = require('events');

class MyStream extends EventEmitter {
    constructor() {
        super();
    }
    write(data) {
        this.emit('data', data);
    }
}

const stream = new MyStream();

stream.on('data', (data) => {
    console.log(`Received data: "${data}"`);
});
stream.write('With ES6');

const dgram = require('dgram');
const message = Buffer.from('Some bytes');
const client = dgram.createSocket('udp4');
client.send(message, 41234, 'localhost', (err) => {
    client.close();
});
const net = require('net');

var server = net.createServer((socket) => {
    socket.end('goodbye\n');
}).on('error', (err) => {
    // handle errors here
    throw err;
});

// grab a random port.
server.listen(() => {
    console.log('opened server on', server.address());
});